﻿namespace SubhadraSolutions.Sharp.Utils.Windows
{
    using System.Windows.Forms;
    
    using SubhadraSolutions.Sharp.Utils.Threading;

    /// <summary>
    /// The WindowsDispatcherProvider class.
    /// </summary>
    public sealed class TargetAsWindowsControlWindowsDispatcherProvider : AbstractFlyweightBasedDispatcherProvider
    {
        /// <summary>
        /// The instance object
        /// </summary>
        private static readonly TargetAsWindowsControlWindowsDispatcherProvider InstanceObject = new TargetAsWindowsControlWindowsDispatcherProvider();

        /// <summary>
        /// Prevents a default instance of the <see cref="TargetAsWindowsControlWindowsDispatcherProvider"/> class from being created.
        /// </summary>
        private TargetAsWindowsControlWindowsDispatcherProvider()
            : base(true)
        {
        }

        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static TargetAsWindowsControlWindowsDispatcherProvider Instance
        {
            get
            {
                return InstanceObject;
            }
        }


        /// <summary>
        /// Gets the dispatcher core.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns></returns>
        protected override IDispatcher GetDispatcherCore(object target)
        {
            var control = target as Control;
            if (control != null)
            {
                return new ControlInvokeDispatcher(control);
            }

            return null;
        }
    }
}
